<?php
/*
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-25 16:15:10
 * @LastEditors: dedeye
 * @LastEditTime: 2020-02-29 13:13:00
 */
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * @name: 返回json 函数
 * @msg: 
 * @param {type} 
 * @return: 
 */
function resultJson($code = 1, $msg = '', $data = null, $status = 200)
{
    return json(compact('code', 'msg', 'data'), $status);
}

/**
 * @name: 转换tp url请求 例子： admin/user/read/<id> 中的转换为 admin/user/read/:id
 * @msg: 
 * @param {type} 
 * @return: 
 */
function getUrlAndParam($rule)
{
    $result = [];
    $baseurl = rtrim(explode('<', $rule)[0], '/');
    preg_match_all("#<([^>]+)>#us", $rule, $result);
    if(count($result[1]) > 0) {
        foreach($result[1] as $v) {
            $baseurl .= '/:' . $v;
        }
    }
    return '/'.$baseurl;
}